


app.controller('AppController', ['$scope', 'FileUploader', function ($scope, FileUploader) {
    var uploader = $scope.uploader = new FileUploader({
        url: 'http://192.168.0.109:9004/Api/File/UploadFile'
    });

    // FILTERS

    uploader.filters.push({
        name: 'imageFilter',
        fn: function (item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });

    // CALLBACKS

    // uploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
    //     console.log(item, filter, options)
    //     // console.info('onWhenAddingFileFailed', item, filter, options);
    // };
    // uploader.onAfterAddingFile = function (fileItem) {
    //     console.info('onAfterAddingFile', fileItem);
    // };
    // uploader.onAfterAddingAll = function (addedFileItems) {
    //     console.info('onAfterAddingAll', addedFileItems);
    // };
    uploader.onBeforeUploadItem = function(item) {
        console.info('onBeforeUploadItem', item);
    };
    uploader.onProgressItem = function(fileItem, progress) {
        console.info('onProgressItem', fileItem, progress);
    };
    // uploader.onProgressAll = function(progress) {
    //     console.info('onProgressAll', progress);
    // };
    // uploader.onSuccessItem = function(fileItem, response, status, headers) {
    //     console.info('onSuccessItem', fileItem, response, status, headers);
    // };
    // uploader.onErrorItem = function(fileItem, response, status, headers) {
    //     console.info('onErrorItem', fileItem, response, status, headers);
    // };
    // uploader.onCancelItem = function(fileItem, response, status, headers) {
    //     console.info('onCancelItem', fileItem, response, status, headers);
    // };
    // uploader.onCompleteItem = function(fileItem, response, status, headers) {
    //     console.info('onCompleteItem', fileItem, response, status, headers);
    // };
    // uploader.onCompleteAll = function() {
    //     console.info('onCompleteAll');
    // };

    // console.info('uploader', uploader);


    // $scope.uploadStatus = $scope.uploadStatus1 = false; //定义两个上传后返回的状态，成功获失败
    //  var uploader = $scope.uploader = new FileUploader({
    //      url: 'upload.php',
    //      queueLimit: 1, //文件个数 
    //      removeAfterUpload: true //上传后删除文件
    //  });
    //  var uploader1 = $scope.uploader1 = new FileUploader({
    //      url: 'upload.php',
    //      queueLimit: 1,
    //      removeAfterUpload: true
    //  });
    //  $scope.clearItems = function () { //重新选择文件时，清空队列，达到覆盖文件的效果
    //      uploader.clearQueue();
    //  }
    //  $scope.clearItems1 = function () {
    //      uploader1.clearQueue();
    //  }
    //  uploader.onAfterAddingFile = function (fileItem) {
    //      $scope.fileItem = fileItem._file; //添加文件之后，把文件信息赋给scope
    //  };
    //  uploader1.onAfterAddingFile = function (fileItem) {
    //      $scope.fileItem1 = fileItem._file; //添加文件之后，把文件信息赋给scope
    //      //能够在这里判断添加的文件名后缀和文件大小是否满足需求。
    //  };
    //  uploader.onSuccessItem = function (fileItem, response, status, headers) {
    //      $scope.uploadStatus = true; //上传成功则把状态改为true
    //  };
    //  uploader1.onSuccessItem = function (fileItem, response, status, headers) {
    //      $scope.uploadStatus1 = true;
    //  }
    //  $scope.UploadFile = function () {
    //      uploader.uploadAll();
    //      uploader1.uploadAll();
    //      if (status) {
    //           if (status1) {
    //               alert('上传成功！');
    //           } else {
    //               alert('证书成功！私钥失败！');
    //           }
    //      } else {
    //           if (status1) {
    //               alert('私钥成功！证书失败！');
    //           } else {
    //               alert('上传失败！');
    //           }
    //      }
    //  }
}]);